<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mailinglist_model
 *
 * @author hassanali
 */
class mailinglist_model extends admin_model {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    /**
     * 
     * @return type
     */
    public function filter($nolimit = false, $selecfeils = '') {
        /* ======== filter ======== */
        // select 
        if (!empty($selecfeils)) {
            $this->db->select($selecfeils, false);
        }
        // Username
        if (metohd_get_uri('email')) {
            $this->db->like('email', metohd_get_uri('email'));
        }
        $limit = metohd_get_uri('dblimit', ADMIN_LIMIT);
        $statrt_limit = get_segment(4, 0);
        if ($nolimit == false) {
            $this->db->limit($limit, $statrt_limit);
        }
        $this->db->order_by('id ' . metohd_get_uri('sort', 'desc'));
        $this->db->from('mailinglist');
        $sql = $this->db->get();
        return $sql->result();
    }


    public function update($user_data, $id) {
        $user_data['user_update'] = $this->admin_id;
        $data['update_date'] = date('Y-m-d H:i:s');
        $this->db->update('mailinglist', $user_data, array('id' => $id));

        $user_data['id'] = $id;
        $this->add_manager_report(array('action' => 'mailinglist-edit', 'contant' => $user_data));
    }

    public function save($user_data) {

        $this->db->insert('mailinglist', $user_data);
        $user_data['id'] = $this->db->insert_id();
        $this->add_manager_report(array('action' => 'mailinglist-add', 'contant' => $user_data));
    }

    public function update_all($id, $data, $where = '') {
        if (count($id) > 0) {
            $this->db->where_in('id', $id);
        }
        $data['user_update'] = $this->admin_id;
        $data['update_date'] = date('Y-m-d H:i:s');
        $this->db->update('mailinglist', $data, $where);

        $data['id'] = join(',', $id);
        $this->add_manager_report(array('action' => 'mailinglist-edit', 'contant' => $data));
    }


    public function delete($id, $img = '') {
        if (is_array($id)) {
            // delete multi user  
            $report_id = join(',', $id);
            foreach ($id as $value) {
                // delete mailinglist
                $this->db->delete('mailinglist', array('id' => $value));
            }
        } else {
 $report_id =$id;
            $this->db->delete('mailinglist', array('id' => $id));
        }



        $this->add_manager_report(array('action' => 'mailinglist-delete', 'contant' => $report_id));
    }

}

?>
